
const FormatInfo = (data) => {
    //获得格式化区块信息
    if(!data){
        return data;
    }
    if(!data.chain_id){
        return data;
    }

    return {
        chain:{
            serverVersion:data.server_version,
            chainId:data.chain_id,                          //区块链id
            blockNum:data.head_block_num                    //区块数量
        }
    }

    //原始数据  get info
    /*{
        "server_version": "b8c1b2c2",
        "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
        "head_block_num": 11572749,
        "last_irreversible_block_num": 11572417,
        "last_irreversible_block_id": "00b094c1a75b1d56328a7579eafefd76c91671096f04a2bffe4d3a04929d344a",
        "head_block_id": "00b0960d26f284da0051c364a3ee1e1661546eb350d59ce453a0aedccd12f90b",
        "head_block_time": "2018-08-17T09:37:10.000",
        "head_block_producer": "eos42freedom",
        "virtual_block_cpu_limit": 34834367,
        "virtual_block_net_limit": 1048576000,
        "block_cpu_limit": 199900,
        "block_net_limit": 1048576
    }*/
};

const FormatGlobal = (data) => {
    //获得格式化全网数据，内存
    if(!data){
        return data;
    }
    if(!data.rows){
        return data;
    }
    if(data.rows.length<1){
        return data;
    }

    let row = data.rows[0];
    let usedRate = (((row.total_ram_bytes_reserved / 1024 / 1024 / 1024).toFixed(2) / (row.max_ram_size / 1024 / 1024 / 1024).toFixed(2)) * 10000 / 100).toFixed()

    return {
        ram:{
            total:(row.max_ram_size / 1024 / 1024 / 1024).toFixed(2),                    //全网内存 格式64G
            used:(row.total_ram_bytes_reserved / 1024 / 1024 / 1024).toFixed(2),         //全网已用内存 格式32G
            stake:(row.total_ram_stake / 1024 / 1024 / 1024).toFixed(2),                 //全网质押内存 格式32G
            usedRate:usedRate                                                            //全网占用比例 格式67.31%
        }
    }

    //原始数据  get_table_rows global
    /*{
        "rows": [{
        "max_block_net_usage": 1048576,
        "target_block_net_usage_pct": 1000,
        "max_transaction_net_usage": 524288,
        "base_per_transaction_net_usage": 12,
        "net_usage_leeway": 500,
        "context_free_discount_net_usage_num": 20,
        "context_free_discount_net_usage_den": 100,
        "max_block_cpu_usage": 200000,
        "target_block_cpu_usage_pct": 1000,
        "max_transaction_cpu_usage": 150000,
        "min_transaction_cpu_usage": 100,
        "max_transaction_lifetime": 3600,
        "deferred_trx_expiration_window": 600,
        "max_transaction_delay": 3888000,
        "max_inline_action_size": 4096,
        "max_inline_action_depth": 4,
        "max_authority_depth": 6,
        "max_ram_size": "74243609600",
        "total_ram_bytes_reserved": "49997578761",
        "total_ram_stake": "27339830075",
        "last_producer_schedule_update": "2018-08-17T06:35:17.000",
        "last_pervote_bucket_fill": "1534487015500000",
        "pervote_bucket": 234657794,
        "perblock_bucket": 37498164,
        "total_unpaid_blocks": 96790,
        "total_activated_stake": "3719373463424",
        "thresh_activated_stake_time": "1529505892000000",
        "last_producer_schedule_size": 21,
        "total_producer_vote_weight": "14444627403843362816.00000000000000000",
        "last_name_close": "2018-08-07T06:13:30.000"
    }
    ],
        "more": false
    }*/
};

export default {
    FormatInfo,
    FormatGlobal
}